package com.spic.business.informatization.before_after_work.controller;

import com.github.pagehelper.util.StringUtil;
import com.spic.business.informatization.before_after_work.domain.MeetingBeforeAfter;
import com.spic.business.informatization.before_after_work.service.AsyncService;
import com.spic.business.informatization.before_after_work.service.IMeetingBeforeAfterService;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.common.security.annotation.PreAuthorize;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 班前班后会主Controller
 *
 * @author yangjie
 * @date 2021-12-20
 */
@RestController
@RequestMapping("/informatization/beforeAfterWork")
public class MeetingBeforeAfterController extends BaseController
{
    private static final Logger log = LoggerFactory.getLogger(MeetingBeforeAfterController.class);
    @Autowired
    private IMeetingBeforeAfterService meetingBeforeAfterService;


//    @Autowired
//    private AsyncService asyncService;
//
//    //private String minioUrl = "http://111.202.164.187:9000";
//    private String minioUrl = "http://62.234.4.59:9000";

    /**
     * 查询班前班后会主列表
     */
    @PreAuthorize(hasPermi = "business/informatization:beforeAfterWork:list")
    @GetMapping("/list")
    public TableDataInfo list(MeetingBeforeAfter meetingBeforeAfter)
    {
        startPage();
        List<MeetingBeforeAfter> list = meetingBeforeAfterService.selectMeetingBeforeAfterList(meetingBeforeAfter);
        return getDataTable(list);
    }

    /**
     * 导出班前班后会主列表
     */
    @PreAuthorize(hasPermi = "business/informatization:beforeAfterWork:export")
    @Log(title = "班前班后会主", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MeetingBeforeAfter meetingBeforeAfter) throws IOException
    {
        List<MeetingBeforeAfter> list = meetingBeforeAfterService.selectMeetingBeforeAfterList(meetingBeforeAfter);
        ExcelUtil<MeetingBeforeAfter> util = new ExcelUtil<MeetingBeforeAfter>(MeetingBeforeAfter.class);
        util.exportExcel(response, list, "班前班后会主数据");
    }

    /**
     * 获取班前班后会主详细信息
     */
    @PreAuthorize(hasPermi = "business/informatization:beforeAfterWork:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(meetingBeforeAfterService.selectMeetingBeforeAfterById(id));
    }

    /**
     * 新增班前班后会主
     */
    @PreAuthorize(hasPermi = "business/informatization:beforeAfterWork:add")
    @Log(title = "班前班后会主", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MeetingBeforeAfter meetingBeforeAfter)
    {
        return AjaxResult.success(meetingBeforeAfterService.insertMeetingBeforeAfter(meetingBeforeAfter));
//        meetingBeforeAfterService.insertMeetingBeforeAfter(meetingBeforeAfter);
//        //if(meetingBeforeAfter.getKeyworkFile() !=null && StringUtil.isEmpty(meetingBeforeAfter.getVedioResult()) ){
//        if(meetingBeforeAfter.getKeyworkFile() !=null){
//            String obsUrl = minioUrl+meetingBeforeAfter.getKeyworkFile().split("1")[0];
//            //String obsUrl = "http://8.218.45.242:8090/static/img/test.mp3";
//            asyncService.getVedioText(obsUrl,meetingBeforeAfter.getId());
//        }
//        return AjaxResult.success("创建成功");
    }

    /**
     * 修改班前班后会主
     */
    @PreAuthorize(hasPermi = "business/informatization:beforeAfterWork:edit")
    @Log(title = "班前班后会主", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MeetingBeforeAfter meetingBeforeAfter)
    {
        return AjaxResult.success(meetingBeforeAfterService.updateMeetingBeforeAfter(meetingBeforeAfter));
//        meetingBeforeAfterService.updateMeetingBeforeAfter(meetingBeforeAfter);
//        //if(meetingBeforeAfter.getKeyworkFile() !=null  && StringUtil.isEmpty(meetingBeforeAfter.getVedioResult())){
//        if(meetingBeforeAfter.getKeyworkFile() !=null){
//            String obsUrl = minioUrl+meetingBeforeAfter.getKeyworkFile().split("1")[0];
//            //String obsUrl = "http://8.218.45.242:8090/static/img/test.mp3";
//            asyncService.getVedioText(obsUrl,meetingBeforeAfter.getId());
//        }
//        return toAjax(1);
    }

    /**
     * 删除班前班后会主
     */
    @PreAuthorize(hasPermi = "business/informatization:beforeAfterWork:remove")
    @Log(title = "班前班后会主", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(meetingBeforeAfterService.deleteMeetingBeforeAfterByIds(ids));
    }

    @GetMapping("/getMeetingBeforWorkCode")
    public AjaxResult selectMeetingBeforWorkCode()
    {
        return AjaxResult.success(meetingBeforeAfterService.selectMeetingBeforWorkCode());
    }
    //校验
    @GetMapping("/getMeetingBeforWorkByMeetingName")
    public AjaxResult getMeetingBeforWorkByMeetingName()
    {
        MeetingBeforeAfter meetingBeforeAfter =  meetingBeforeAfterService.getMeetingBeforWorkByMeetingName();
        return AjaxResult.success(meetingBeforeAfter);
    }

    @GetMapping("filterDirtyData")
    public AjaxResult filterDirtyData() {
        meetingBeforeAfterService.filterDirtyData();
        return AjaxResult.success();
    }
}
